/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.fee.core.repository.mapper;


import info.peigen.hotpot.business.fee.core.repository.entity.FeeRuleEntity;
import info.peigen.hotpot.business.fee.facade.enums.FeeMethod;
import info.peigen.hotpot.business.fee.facade.enums.FeeProductCode;
import info.peigen.hotpot.business.fee.facade.query.result.info.CustomerFeeRuleInfo;
import info.peigen.hotpot.common.core.enums.Currency;
import info.peigen.hotpot.component.data.repository.beetlsql.mapper.AbstractBeetlSqlMapper;
import org.beetl.sql.mapper.annotation.Select;
import org.beetl.sql.mapper.annotation.Sql;
import org.beetl.sql.mapper.annotation.Update;

import java.util.List;

/**
 * <b>(FeeRuleMapper)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/8/1
 */
@SuppressWarnings("AlibabaAbstractMethodOrInterfaceMethodMustUseJavadoc")
public interface FeeRuleMapper extends AbstractBeetlSqlMapper<FeeRuleEntity> {
    @Sql("select * from fee_rule where rule_id = ?")
    @Select
    FeeRuleEntity findByRuleId(String ruleId);

    @Sql("select * from fee_rule where rule_id = ? for update")
    @Select
    FeeRuleEntity lockByRuleId(String ruleId);

    @Sql("select * from fee_rule where account_id = ? and code = ?")
    @Select
    FeeRuleEntity findByAccountIdAndProductCode(String accountId, FeeProductCode productCode);

    @Sql("select * from fee_rule where account_id = ?")
    @Select
    List<FeeRuleEntity> listByAccountId(String accountId);

    @Sql("delete from fee_rule where rule_id = ?")
    @Update
    void deleteByRuleId(String ruleId);

    @Sql("delete from fee_rule where account_id = ?")
    @Update
    void deleteByAccountId(String accountId);

    @Sql("delete from fee_rule where code = ? and method = ? and currency = ?")
    @Select
    void deleteByProductCodeAndMethodAndCurrency(FeeProductCode productCode, FeeMethod method, Currency currency);

    @Sql("delete from fee_rule where station_parent_id = ?")
    @Update
    void deleteByStationParentId(String stationParentId);

    @Sql("delete from fee_rule where partner_id = ?")
    @Update
    void deleteByPartnerId(String partnerId);

    @Sql("delete from fee_rule where name = ?")
    @Update
    void deleteByName(String name);

    long queryFeeRuleCount(String customerId, String accountId, String feeAccountId, String method, String code, String type, String currency);

    List<CustomerFeeRuleInfo> queryFeeRulePage(String customerId, String accountId, String feeAccountId, String method, String code, String type, String currency, Integer offset, Integer limit);
}